package com.das.mechanic_base.mvp.view.create;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.R2;
import com.das.mechanic_base.adapter.alone.X3FirstAloneCameraAdapter;
import com.das.mechanic_base.adapter.alone.X3FirstAloneRichCameraAdapter;
import com.das.mechanic_base.adapter.create.CarBodyAdapter;
import com.das.mechanic_base.adapter.create.FirstAloneSelectAdapter;
import com.das.mechanic_base.app.X3Constent;
import com.das.mechanic_base.base.X3BaseActivity;
import com.das.mechanic_base.base.X3IBaseView;
import com.das.mechanic_base.bean.alone.AloneImageAndRecordBean;
import com.das.mechanic_base.bean.alone.CameraCropBean;
import com.das.mechanic_base.bean.alone.SpeechBean;
import com.das.mechanic_base.bean.camera.CameraBean;
import com.das.mechanic_base.bean.camera.CameraCloseBean;
import com.das.mechanic_base.bean.common.AwsFileBean;
import com.das.mechanic_base.bean.create.MapReceiveStatusBean;
import com.das.mechanic_base.bean.create.ServiceInfoBean;
import com.das.mechanic_base.bean.even.DeleteFriends;
import com.das.mechanic_base.bean.main.CarPicAndColorBean;
import com.das.mechanic_base.bean.main.DetectionNewBean;
import com.das.mechanic_base.bean.main.HomeMainCarBean;
import com.das.mechanic_base.def.finish.X3WorkType;
import com.das.mechanic_base.mapi.api.NetWorkHttp;
import com.das.mechanic_base.mapi.response.HttpCallBack;
import com.das.mechanic_base.mapi.schedulers.RxSchedulersHelper;
import com.das.mechanic_base.mvp.contract.create.X3ServiceInfoContract;
import com.das.mechanic_base.mvp.presenter.create.X3ServiceInfoPresenter;
import com.das.mechanic_base.mvp.view.camera.X3CameraPhotoActivity;
import com.das.mechanic_base.mvp.view.finish.X3WorkFinishActivity;
import com.das.mechanic_base.utils.AverageGapItemDecoration;
import com.das.mechanic_base.utils.LanguageUtiles;
import com.das.mechanic_base.utils.SoftKeyboardStateHelper;
import com.das.mechanic_base.utils.X3EdittextWatcher;
import com.das.mechanic_base.utils.X3FileUtils;
import com.das.mechanic_base.utils.X3GlideNewUtils;
import com.das.mechanic_base.utils.X3ScreenUtils;
import com.das.mechanic_base.utils.X3StatusBarUtil;
import com.das.mechanic_base.utils.X3StringUtils;
import com.das.mechanic_base.utils.X3Utils;
import com.das.mechanic_base.widget.X3AloneSoundView;
import com.das.mechanic_base.widget.X3BottomAddRichDialog;
import com.das.mechanic_base.widget.X3BottomEditCarDialog;
import com.das.mechanic_base.widget.X3EditFaultightDialog;
import com.das.mechanic_base.widget.X3FirstAloneOilView;
import com.das.mechanic_base.widget.X3MemberButtonView;
import com.google.gson.Gson;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.hjq.toast.ToastUtils;
import com.iflytek.cloud.RecognizerListener;
import com.iflytek.cloud.RecognizerResult;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechRecognizer;
import com.kproduce.roundcorners.RoundImageView;
import com.kproduce.roundcorners.RoundRelativeLayout;
import com.kproduce.roundcorners.RoundTextView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import razerdp.basepopup.BasePopupWindow;
import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;

public class X3FirstAloneActivity extends X3BaseActivity<X3ServiceInfoPresenter> implements FirstAloneSelectAdapter.IOnClickFirstAlone,
        X3BottomAddRichDialog.IOnSelectRich, X3ServiceInfoContract.View, CarBodyAdapter.IOnCarBodyEdit, X3MemberButtonView.IOnClickAffirm, X3FirstAloneRichCameraAdapter.IOnItemCameraClick {

    @BindView(R2.id.rl_header)
    RelativeLayout rl_header;
    @BindView(R2.id.tv_title)
    TextView tv_title;
    @BindView(R2.id.et_input)
    EditText et_input;
    @BindView(R2.id.ll_start)
    LinearLayout ll_start;
    @BindView(R2.id.iv_voice)
    ImageView iv_voice;
    @BindView(R2.id.as_view)
    X3AloneSoundView as_view;
    @BindView(R2.id.iv_clear)
    ImageView iv_clear;
    @BindView(R2.id.rlv_rich)
    RecyclerView rlv_rich;
    @BindView(R2.id.rlv_light)
    RecyclerView rlv_light;
    @BindView(R2.id.rlv_tool)
    RecyclerView rlv_tool;
    @BindView(R2.id.rv_img)
    RoundImageView rv_img;
    @BindView(R2.id.tv_camera_notice)
    TextView tv_camera_notice;
    @BindView(R2.id.rv_camera)
    RoundTextView rv_camera;
    @BindView(R2.id.rl_oil)
    RoundRelativeLayout rl_oil;
    @BindView(R2.id.rl_light)
    RoundRelativeLayout rl_light;
    @BindView(R2.id.rl_note)
    RoundRelativeLayout rl_note;
    @BindView(R2.id.rl_jew)
    RoundRelativeLayout rl_jew;
    @BindView(R2.id.rl_car)
    RoundRelativeLayout rl_car;
    @BindView(R2.id.rl_thing)
    RoundRelativeLayout rl_thing;
    @BindView(R2.id.tv_oil)
    TextView tv_oil;
    @BindView(R2.id.tv_light)
    TextView tv_light;
    @BindView(R2.id.tv_rich)
    TextView tv_rich;
    @BindView(R2.id.tv_body)
    TextView tv_body;
    @BindView(R2.id.tv_tool)
    TextView tv_tool;
    @BindView(R2.id.tv_text)
    TextView tv_text;
    @BindView(R2.id.ov_view)
    X3FirstAloneOilView ov_view;
    @BindView(R2.id.il_left)
    RelativeLayout il_left;
    @BindView(R2.id.il_middle)
    RelativeLayout il_middle;
    @BindView(R2.id.il_right)
    RelativeLayout il_right;
    @BindView(R2.id.rlv_body)
    RecyclerView rlv_body;
    @BindView(R2.id.rv_check)
    X3MemberButtonView rv_check;
    @BindView(R2.id.nv_view)
    NestedScrollView nv_view;
    @BindView(R2.id.v_bottom)
    View v_bottom;
    @BindView(R2.id.rlv_rich_pic)
    RecyclerView rlv_rich_pic;

    /**
     * 在损伤界面开始拍照的时候，是点击第几个icon进行的拍照，当拍照完成后根据这个索引将新数据插入list，对recycleview进行刷新
     */
    private int imageIndex;

    private InputMethodManager imm;

    private SpeechRecognizer mIat;

    private FirstAloneSelectAdapter thingAdapter;
    private FirstAloneSelectAdapter lightAdapter;
    private FirstAloneSelectAdapter toolAdapter;
    //车辆损伤的adapter需要验证下
    private X3FirstAloneRichCameraAdapter richPicAdapter;

    private String lightPath;
    private X3EditFaultightDialog editLightDialog;
    private X3BottomAddRichDialog richDialog;
    private long receiveBaseId;
    // 是否是故障灯 其余是外观损伤
    private boolean isLight;
    // 当前拍照是不是贵重物品
    private boolean isRich;
    private X3BottomEditCarDialog editCarDialog;
    // 拍摄外观的tag 也就是对应的sn
    private String take_tag = "";
    private CarBodyAdapter bodyAdapter;
    private List<DetectionNewBean> mList;
    private boolean isFirst;
    private List<String> selectCarList = new ArrayList<>();

    /**
     * 贵重物品照片list
     */
    private List<AloneImageAndRecordBean> richPicShowList;
    /**
     * 贵重物品图片的位置索引
     */
    private int richPicIndex;

    @Override
    protected int getLayoutId() {
        EventBus.getDefault().register(this);
        return R.layout.activity_first_alone;
    }

    @Override
    protected void initView() {
        X3StatusBarUtil.darkMode(this);
        rl_header.setBackgroundColor(Color.parseColor("#F5F5F7"));
        rl_header.setPadding(0,X3StatusBarUtil.getStatusBarHeight(this),0,0);

        receiveBaseId = getIntent().getLongExtra("receiveBaseId", 0L);
        isFirst = getIntent().getBooleanExtra("isFirst", false);

        imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        tv_title.setText(getString(R.string.x3_car_alone_title));

        if (mPresenter != null) {
            mPresenter.getDetectionFirstInfo(receiveBaseId);
        }

        et_input.addTextChangedListener(new X3EdittextWatcher() {
            @Override
            protected void textInputAfter(String content) {
                iv_clear.setVisibility(X3StringUtils.isEmpty(content) ? View.GONE : View.VISIBLE);
            }
        });

        rlv_body.setLayoutManager(new LinearLayoutManager(this));
        bodyAdapter = new CarBodyAdapter(this);
        rlv_body.setAdapter(bodyAdapter);
        bodyAdapter.setiOnCarBodyEdit(this);

        rlv_rich.setLayoutManager(new GridLayoutManager(this,3));
        thingAdapter = new FirstAloneSelectAdapter(this,1,true);
        rlv_rich.setAdapter(thingAdapter);
        thingAdapter.setiOnClickFirstAlone(this);

        rlv_rich_pic.setLayoutManager(new GridLayoutManager(this,3));
        rlv_rich_pic.addItemDecoration(new AverageGapItemDecoration(10,10,0));
        richPicAdapter = new X3FirstAloneRichCameraAdapter(this,true,0,9);

        rlv_rich_pic.setAdapter(richPicAdapter);
        richPicAdapter.setiOnItemCameraClick(this);

        rlv_light.setLayoutManager(new GridLayoutManager(this,3));
        lightAdapter = new FirstAloneSelectAdapter(this,0,true);
        rlv_light.setAdapter(lightAdapter);
        lightAdapter.setiOnClickFirstAlone(this);

        rlv_tool.setLayoutManager(new GridLayoutManager(this,3));
        toolAdapter = new FirstAloneSelectAdapter(this,2,false);
        rlv_tool.setAdapter(toolAdapter);

        initFeatureData(il_left);
        initFeatureData(il_middle);
        initFeatureData(il_right);

        rv_check.changeBtnStatus(true);
        rv_check.setiOnClickAffirm(this);

        keyBoardParams();
    }

    Handler keyBoardHandler = new Handler();
    //键盘高度参数
    private void keyBoardParams(){
        SoftKeyboardStateHelper softKeyboardStateHelper = new SoftKeyboardStateHelper(this.getWindow().getDecorView());
        softKeyboardStateHelper.addSoftKeyboardStateListener(new SoftKeyboardStateHelper.SoftKeyboardStateListener() {
            @Override
            public void onSoftKeyboardOpened(int keyboardHeightInPx) {
                adjustBottomViewParams(keyboardHeightInPx-X3StatusBarUtil.getStatusBarHeight(X3FirstAloneActivity.this) + X3ScreenUtils.dip2px(5,X3FirstAloneActivity.this));
            }

            @Override
            public void onSoftKeyboardClosed() {
                keyBoardHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        adjustBottomViewParams(X3ScreenUtils.dip2px(12,X3FirstAloneActivity.this));
                    }
                },X3Constent.getKeyBoardDelayed());
            }
        });
    }

    private void adjustBottomViewParams(int pxH){
        if (v_bottom != null){
            try {
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) v_bottom.getLayoutParams();
                layoutParams.height =  pxH;
                layoutParams.width = 1;
                v_bottom.setLayoutParams(layoutParams);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    /**
     * 外观损伤
     * @param rl_parent
     */
    private void initFeatureData(RelativeLayout rl_parent) {
        for (int i = 0; i < rl_parent.getChildCount(); i++) {
            ImageView view = (ImageView) rl_parent.getChildAt(i);
            String tag = (String) view.getTag();
            if (X3StringUtils.isEmpty(tag)) {
                continue;
            }
            view.setImageResource(R.mipmap.x3_first_alone_car_normal);
            view.setOnClickListener(v -> {
                take_tag = (String) view.getTag();
                isLight = false;
                isRich = false;
                startEditCar(null,true,new ArrayList<String>());

//                startCameraView(4);
            });
        }
    }

    private void startCameraView(int isAlbum) {
        Intent intent = new Intent(this, X3CameraPhotoActivity.class);
        intent.putExtra("allNum",1);
        intent.putExtra("isAlbum",isAlbum);//4 外观损伤
        startActivity(intent);
        overridePendingTransition(R.anim.activity_enter, 0);
    }

    private void startCameraView(int isAlbum,int currentCount) {
        Intent intent = new Intent(this, X3CameraPhotoActivity.class);
        intent.putExtra("allNum",9 - currentCount);
        intent.putExtra("isAlbum",isAlbum);//4 外观损伤
        startActivity(intent);
        overridePendingTransition(R.anim.activity_enter, 0);
    }

    @Override
    protected X3ServiceInfoPresenter createPresenter() {
        return new X3ServiceInfoPresenter();
    }

    @OnClick({R2.id.iv_back,R2.id.iv_voice,R2.id.iv_clear,R2.id.tv_end,R2.id.rv_img,R2.id.rv_end,R2.id.rv_camera})
    public void onViewClick(View view) {
        if(view.getId() == R.id.iv_back) {
            finish();
        }else if (view.getId() == R.id.iv_voice) {
            // 语音识别
            XXPermissions.with(this)
                    .permission(Permission.RECORD_AUDIO)
                    .request(new OnPermissionCallback() {
                        @Override
                        public void onGranted(List<String> permissions, boolean all) {
                            if (all) {
                                startSoundEdit();
                            } else {
                                XXPermissions.startPermissionActivity(X3FirstAloneActivity.this, permissions);
                            }
                        }

                        @Override
                        public void onDenied(List<String> permissions, boolean never) {
                            XXPermissions.startPermissionActivity(X3FirstAloneActivity.this, permissions);
                        }
                    });
        }else if (view.getId() == R.id.iv_clear) {
            et_input.setText("");

        }else if (view.getId() == R.id.tv_end) {
            isShowSound(false);
            if (mIat != null) {
                mIat.stopListening();
                mIat = null;
            }
        }else if (view.getId() == R.id.rv_img) {
            // 未拍照时跳转拍照 拍照后 跳转查看大图
            if (rv_camera.getVisibility() == View.VISIBLE) {
                // 跳转查看大图
                List<String> imgList = new ArrayList<>();
                imgList.add(lightPath);
                X3Utils.startShowImage(this,imgList,0);

            }else {
                isLight = true;
                isRich = false;
                startCameraView(3);
            }
        }else if(view.getId() == R.id.rv_camera) {
            isLight = true;
            isRich = false;
            startCameraView(3);

        }else if (view.getId() == R.id.rv_end) {
            finish();
        }
    }

    /**
     * 语音听写
     */
    private void startSoundEdit() {
        mIat = SpeechRecognizer.createRecognizer(this, i -> Log.e("SSSS", "初始化：" + i));

        //设置语法ID和 SUBJECT 为空，以免因之前有语法调用而设置了此参数；或直接清空所有参数，具体可参考 DEMO 的示例。
        mIat.setParameter(SpeechConstant.CLOUD_GRAMMAR, null);
        mIat.setParameter(SpeechConstant.SUBJECT, null);
        //设置返回结果格式，目前支持json,xml以及plain 三种格式，其中plain为纯听写文本内容
        mIat.setParameter(SpeechConstant.RESULT_TYPE, "json");

        //此处engineType为“cloud”
        mIat.setParameter(SpeechConstant.ENGINE_TYPE, "cloud");
        //设置语音输入语言，zh_cn为简体中文
        if (LanguageUtiles.isZhRCN()) {
            mIat.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
        }else {
            mIat.setParameter(SpeechConstant.LANGUAGE, "en_us");
        }
        //设置结果返回语言
        mIat.setParameter(SpeechConstant.ACCENT, "mandarin");
        // 设置语音前端点:静音超时时间，单位ms，即用户多长时间不说话则当做超时处理
        //取值范围{1000～10000}
        mIat.setParameter(SpeechConstant.VAD_BOS, "10000");
        //设置语音后端点:后端点静音检测时间，单位ms，即用户停止说话多长时间内即认为不再输入，
        //自动停止录音，范围{0~10000}
        mIat.setParameter(SpeechConstant.VAD_EOS, "10000");
        //设置标点符号,设置为"0"返回结果无标点,设置为"1"返回结果有标点
        mIat.setParameter(SpeechConstant.ASR_PTT, "1");

        mIat.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");

        //开始识别，并设置监听器
        mIat.startListening(new RecognizerListener() {
            @Override
            public void onVolumeChanged(int i, byte[] bytes) {

            }

            @Override
            public void onBeginOfSpeech() {
                isShowSound(true);
            }

            @Override
            public void onEndOfSpeech() {
                isShowSound(false);
            }

            @Override
            public void onResult(RecognizerResult recognizerResult, boolean b) {
                if (isFinishing()) {
                    return;
                }
                SpeechBean speechBean = new Gson().fromJson(recognizerResult.getResultString(), SpeechBean.class);
                List<SpeechBean.WsBean> ws = speechBean.getWs();
                String strContent = "";
                for (SpeechBean.WsBean wsBean : ws) {
                    strContent = strContent + wsBean.getCw().get(0).getW();
                }
                String content = et_input.getText().toString() + strContent;
                et_input.setText(content);
                if (!X3StringUtils.isEmpty(content)) {
                    if (content.length() < 1000) {
                        et_input.setSelection(content.length());
                    }
                }

            }

            @Override
            public void onError(SpeechError speechError) {

            }

            @Override
            public void onEvent(int i, int i1, int i2, Bundle bundle) {

            }
        });
    }

    /**
     * true ? 相当于点击了语音输入 显示语音输入的相关布局 ： 显示创建任务的布局
     *
     * @param showSound
     */
    private void isShowSound(boolean showSound) {

        ll_start.setVisibility(showSound ? View.VISIBLE : View.GONE);
        iv_voice.setVisibility(showSound ? View.GONE : View.VISIBLE);
        if (showSound) {
            as_view.startAnim();
            imm.hideSoftInputFromWindow(et_input.getWindowToken(), 0);
            nv_view.post(() -> nv_view.fullScroll(View.FOCUS_DOWN));
        } else {
            as_view.stopAnim();
            et_input.requestFocus();
            imm.showSoftInput(et_input, 0);
        }

    }

    @Override
    protected void onDestroy() {
        EventBus.getDefault().unregister(this);
        if (mIat != null) {
            isShowSound(false);
            mIat.stopListening();
        }
        super.onDestroy();
    }

    /**
     * 不选择照片直接关闭拍照界面
     * @param closeBean
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onPictureOrVideoClose(CameraCloseBean closeBean) {
        if (editCarDialog != null && opStatus){
            editCarDialog.dismiss();
        }
    }

    /**
     * 从相册中选取图片 或者拍照 数据都会从这个方法进入
     * @param cameraBean
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onGetPictureOrVideo(CameraBean cameraBean) {
        opStatus = false;
        if (cameraBean == null) {
            return;
        }
        switch ((int) cameraBean.resultCode) {
            //图片或者视频
            case X3Constent.CODE_CAMERA_REQUEST:
            case X3Constent.CODE_GALLERY_REQUEST:
                if (cameraBean.cameraData == null) {
                    return;
                }
                List<String> pList = (List<String>) cameraBean.cameraData;
                if (X3StringUtils.isListEmpty(pList)) {
                    return;
                }
                if (isLight) {
                    lightPath = pList.get(0);
                    X3GlideNewUtils.loadNormalImage(this,lightPath,rv_img,0);
                    rv_camera.setVisibility(View.VISIBLE);
                    tv_camera_notice.setVisibility(View.GONE);
                    showEditLight(true,lightPath);

                } else if (isRich){

                    refreshRichPicList(cameraBean);
                    isRich = false;

                } else {
                    // 编辑车损
//                    startEditCar(pList.get(0),true,selectCarList);
//                    selectCarList = new ArrayList<>();

                    refreshEditCarPicList(cameraBean);
                }

                break;
            default:
                break;
        }
    }

    //获取的贵重物品的照片数据
    private void refreshRichPicList(CameraBean cameraBean){
        onRichGetPicRefreshPicRlv(cameraBean,richPicIndex);
    }

    // 车损拍照返回的照片数据
    private void refreshEditCarPicList(CameraBean cameraBean){
        if (editCarDialog != null) {
            editCarDialog.onGetPicRefreshPicRlv(cameraBean,imageIndex);
        }
    }

    /**
     * 是不是点击外观损伤的圆点进入拍照的
     */
    private boolean opStatus;

    public void startEditCar(List<String> paths,boolean isCamera,List<String> selectCarList) {
        opStatus = isCamera;
        editCarDialog = new X3BottomEditCarDialog(this);
        editCarDialog.show();
        editCarDialog.setiOnEditCar(new X3BottomEditCarDialog.IOnEditCar() {
            @Override
            public void iOnEditCarToCamera(List<String> sList) {
                X3FirstAloneActivity.this.selectCarList = sList;
                if (!isCamera) {
                    return;
                }
            }

            @Override
            public void iOnEditCarCameraAgain(String sn,List<String> sList) {
                X3FirstAloneActivity.this.selectCarList = sList;
                take_tag = sn;
                isLight = false;
                isRich = false;
                startCameraView(4,sList.size());
            }

            @Override
            public void iOnEditCarSuccess(DetectionNewBean.QuestionToItemDetectionBean detectionBean,String sn) {
                if (bodyAdapter == null) {
                    return;
                }
                List<DetectionNewBean.QuestionToItemDetectionBean> detectionBeans = bodyAdapter.getmList();
                if (X3StringUtils.isListEmpty(detectionBeans)) {
                    detectionBeans = new ArrayList<>();
                    detectionBeans.add(detectionBean);
                }else {
                    boolean isHave = false;
                    for (int i = 0; i < detectionBeans.size(); i++) {
                        String sn1 = detectionBeans.get(i).sn;
                        if (!sn1.equals(sn)) {
                            continue;
                        }
                        isHave = true;
                        detectionBeans.remove(i);
                        detectionBeans.add(i,detectionBean);
                    }
                    if (!isHave) {
                        detectionBeans.add(detectionBean);
                    }
                }
                if (bodyAdapter != null) {
                    bodyAdapter.changeCarBody(detectionBeans);
                }
                changeImageSelect(detectionBeans);
            }

        });
        editCarDialog.setiOnTakeCamera(new X3BottomEditCarDialog.IOnTakeCamera() {
            @Override
            public void iOnClickTakeCamera(int imageIndex) {
                X3FirstAloneActivity.this.imageIndex = imageIndex;
                startCameraView(4,imageIndex);
            }
        });

        editCarDialog.showEditCar(take_tag,paths,receiveBaseId,selectCarList,isCamera);

    }

    @Override
    public void iOnClickSelectThing(List<DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean> mList) {

    }

    @Override
    public void iOnClickAddThing(int type,String path) {
        switch (type) {
            case 0:
                showEditLight(false,path);

                break;
            case 1:
                // 添加贵重物品
                if (richDialog == null) {
                    richDialog = new X3BottomAddRichDialog(this);
                    richDialog.setiOnSelectTag(this);
                }
                richDialog.setAdjustInputMethod(true)
                        .setBackPressEnable(true)
                        .setAutoShowInputMethod(richDialog.findViewById(R.id.ed_input), true)
                        .setAdjustInputMode(R.id.ed_input, BasePopupWindow.FLAG_KEYBOARD_ALIGN_TO_ROOT | BasePopupWindow.FLAG_KEYBOARD_ANIMATE_ALIGN)
                        .showPopupWindow();

                break;
        }
    }

    private void showEditLight(boolean isCamera, String path) {
        List<DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean> questionListBeans = lightAdapter.getmList();
        List<String> sList = new ArrayList<>();
        if (!X3StringUtils.isListEmpty(questionListBeans)) {
            for (DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean listBean : questionListBeans) {
                sList.add(listBean.answer);
            }
        }
        // 故障灯
        if (editLightDialog == null) {
            editLightDialog = new X3EditFaultightDialog(this);
        }
        editLightDialog.show();
        editLightDialog.setQuestionSystemSn("sys_light_new_001", receiveBaseId,isCamera,path,sList);
        editLightDialog.setiOnEditLight(new X3EditFaultightDialog.IOnEditLight() {
            @Override
            public void iOnEditLight(DetectionNewBean.QuestionToItemDetectionBean detectionBean, String questionSystemSn) {
                if (lightAdapter == null) {
                    return;
                }
                if (X3StringUtils.isListEmpty(mList)) {
                    return;
                }
                for (int i = 0; i < mList.size(); i++) {
                    DetectionNewBean newBean = mList.get(i);
                    if (!"sys_light_new_001".equals(newBean.questionToSystemSn)) {
                        continue;
                    }
                    newBean.url = detectionBean.itemUrlList.get(0);
                    List<DetectionNewBean.QuestionToItemDetectionBean> newList = new ArrayList<>();
                    newList.add(detectionBean);
                    newBean.questionToItemDetectionFirstVOList = newList;
                    mList.remove(i);
                    mList.add(i,newBean);

                    if (X3StringUtils.isListEmpty(newList)) {
                        if (lightAdapter != null) {
                            lightAdapter.changeData(new ArrayList<>(),newBean.url);
                        }
                        return;
                    }
                    List<DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean> questionList = newList.get(0).questionList;
                    if (X3StringUtils.isListEmpty(questionList)) {
                        questionList = new ArrayList<>();
                    }
                    if (lightAdapter != null) {
                        lightAdapter.changeData(questionList,newBean.url);
                    }
                }
            }
        });
    }

    @Override
    public void iOnSelectRich(String content) {
        if (X3StringUtils.isEmpty(content)) {
            return;
        }
        if (thingAdapter != null) {
            thingAdapter.addFirstAloneData(new DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean(content,R.mipmap.first_alone_other,true));
        }
    }

    @Override
    public void getReceiveSuccess(ServiceInfoBean infoBean) {

    }

    @Override
    public void getReceiveStatusListSuccess(MapReceiveStatusBean statusBean) {

    }

    @Override
    public void getReceiveBase(HomeMainCarBean mainCarBean) {

    }

    @Override
    public void updateCarTypeSuccess() {

    }
    @Override
    public void updateCarTypeFail() {

    }
    @Override
    public void uploadCarPicSuccess(CarPicAndColorBean colorBean) {

    }

    @Override
    public void getVin(String vin) {

    }

    @Override
    public void closeReceiveBaseSuccess() {

    }

    @Override
    public void getDetectionFirstInfoSuccess(List<DetectionNewBean> mList) {
        if (X3StringUtils.isListEmpty(mList)) {
            return;
        }
        this.mList = mList;
        for (DetectionNewBean newBean : mList) {
            if (newBean == null) {
                continue;
            }
            showDetectionItem(newBean);
        }
    }

    /**
     * 根据sn获取对应圆点view
     * @param sn
     * @return
     */
    public ImageView getSelectCarImageView(String sn) {
        for (int i = 0; i < il_left.getChildCount(); i++) {
            ImageView view = (ImageView) il_left.getChildAt(i);
            String tag = (String) view.getTag();
            if (X3StringUtils.isEmpty(tag)) {
                continue;
            }
            if (!sn.equals(tag)) {
                continue;
            }
            return view;
        }
        for (int i = 0; i < il_middle.getChildCount(); i++) {
            ImageView view = (ImageView) il_middle.getChildAt(i);
            String tag = (String) view.getTag();
            if (X3StringUtils.isEmpty(tag)) {
                continue;
            }
            if (!sn.equals(tag)) {
                continue;
            }
            return view;
        }
        for (int i = 0; i < il_right.getChildCount(); i++) {
            ImageView view = (ImageView) il_right.getChildAt(i);
            String tag = (String) view.getTag();
            if (X3StringUtils.isEmpty(tag)) {
                continue;
            }
            if (!sn.equals(tag)) {
                continue;
            }
            return view;
        }
        return null;
    }

    /**
     * 增添每一项的题目
     * @param detectionBean
     */
    private void showDetectionItem(DetectionNewBean detectionBean) {
        List<DetectionNewBean.QuestionToItemDetectionBean> contentList = detectionBean.questionToItemDetectionFirstVOList;
        String questionToSystemSn = detectionBean.questionToSystemSn;

        if (X3StringUtils.isEmpty(questionToSystemSn)) {
            return;
        }
        String content = "";
        List<DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean> allList = new ArrayList<>();
        if (!X3StringUtils.isListEmpty(contentList)) {
            for (DetectionNewBean.QuestionToItemDetectionBean contentBean : contentList) {
                List<DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean> questionList = contentBean.questionList;
                if (X3StringUtils.isListEmpty(questionList)) {
                    questionList = new ArrayList<>();
                }
                if ("sys_light_new_001".equals(questionToSystemSn)) {
                    for (int i = 0; i < questionList.size(); i++) {
                        DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean listBean = questionList.get(i);
                        listBean.iconRes = X3StringUtils.getLightSpan(listBean.answer);
                        questionList.remove(i);
                        questionList.add(i,listBean);
                    }
                }

                allList.addAll(questionList);
                for (DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean questionBean : questionList) {
                    if (X3StringUtils.isEmpty(content)) {
                        content = questionBean.answer;
                    }else {
                        content = content + ", " + questionBean.answer;
                    }
                }
            }
        }
        switch (questionToSystemSn) {
            case "sys_oil_001":
                // 进厂油量
                rl_oil.setVisibility(View.VISIBLE);
                tv_oil.setText(detectionBean.toSystem);
                if (!X3StringUtils.isEmpty(content)) {
                    double v = Double.parseDouble(content);
                    int prograss = (int) (v * 8 / 100);
                    ov_view.changePrograss(prograss - 1);
                }

                break;
            case "sys_light_new_001":
                // 故障灯
                rl_light.setVisibility(View.VISIBLE);
                tv_light.setText(detectionBean.toSystem);
                String url = detectionBean.url;
                if (X3StringUtils.isEmpty(url)) {
                    rv_img.setBackgroundColor(ContextCompat.getColor(this,R.color.bg_F5F5F7));
                    rv_camera.setVisibility(View.GONE);
                    tv_camera_notice.setVisibility(View.VISIBLE);
                }else {
                    lightPath = url;
                    X3GlideNewUtils.loadNormalImage(this,X3StringUtils.getImageUrl(url),rv_img,0);
                    rv_camera.setVisibility(View.VISIBLE);
                    tv_camera_notice.setVisibility(View.GONE);
                }

                if (!X3StringUtils.isListEmpty(allList)) {
                    if (lightAdapter != null) {
                        lightAdapter.changeData(allList,url);
                    }
                }

                break;
            case "sys_thing_001":
                // 贵重物品
                rl_thing.setVisibility(View.VISIBLE);
                tv_rich.setText(detectionBean.toSystem);
                if (!X3StringUtils.isListEmpty(allList)) {
                    if (thingAdapter != null) {
                        thingAdapter.changeData(allList,"");
                    }
                }

                if (!X3StringUtils.isListEmpty(detectionBean.urlList)) {
                    showRichPics(detectionBean.urlList,true);
                }

                break;
            case "sys_feature_new_001":
                // 外观损伤
                rl_car.setVisibility(View.VISIBLE);
                tv_body.setText(detectionBean.toSystem);
                if (!X3StringUtils.isListEmpty(contentList)) {
                    changeImageSelect(contentList);
                    for (int i = 0; i < contentList.size(); i++) {
                        DetectionNewBean.QuestionToItemDetectionBean contentBean = contentList.get(i);
//                        contentBean.itemUrl = X3StringUtils.getImageUrl(contentBean.itemUrl);
                        contentList.remove(i);
                        contentList.add(i,contentBean);
                    }
                    if (bodyAdapter != null) {
                        bodyAdapter.changeCarBody(contentList);
                    }
                }

                break;
            case "sys_tools_001":
                // 随车工具
                rl_jew.setVisibility(View.VISIBLE);
                tv_tool.setText(detectionBean.toSystem);
                if (!X3StringUtils.isListEmpty(allList)) {
                    if (toolAdapter != null) {
                        toolAdapter.changeData(allList,"");
                    }
                }

                break;
            case "sys_remark_001":
                // 车主备注
                rl_note.setVisibility(View.VISIBLE);
                et_input.setText(content);

                break;
        }
    }

    /**
     * 改变圆点的颜色
     * @param contentList
     */
    private void changeImageSelect(List<DetectionNewBean.QuestionToItemDetectionBean> contentList) {
        initFeatureData(il_left);
        initFeatureData(il_middle);
        initFeatureData(il_right);
        if (X3StringUtils.isListEmpty(contentList)) {
            return;
        }
        for (DetectionNewBean.QuestionToItemDetectionBean contentBean : contentList) {
            String sn = contentBean.sn;
            // 外观损伤需要改变圆点的颜色
            ImageView selectView = getSelectCarImageView(sn);
            if (selectView != null) {
                selectView.setImageResource(R.mipmap.x3_first_alone_car_error);
            }
        }
    }

    @Override
    public void iOnCarBodyEdit(String sn, List<String> path,List<String> selectCarList) {
        take_tag = sn;
        startEditCar(path,false,selectCarList);
    }

    @Override
    public void iOnCarBodyDelete(List<DetectionNewBean.QuestionToItemDetectionBean> mList) {
        changeImageSelect(mList);
    }

    @Override
    public void iOnReviewImage(List<String> imageUrls,int index) {
        X3Utils.startShowImage(this,imageUrls,index);
    }

    @Override
    public void iOnClickAffirm() {
        boolean commitFlag = true;
        if (X3StringUtils.isListEmpty(mList)) {
            rv_check.reset();
            return;
        }
        int currentPrograss = ov_view.getCurrentPrograss();
        if (currentPrograss >= 0) {
            double oil = (currentPrograss + 1) * 12.5;

            for (int i = 0; i < mList.size(); i++) {
                DetectionNewBean newBean = mList.get(i);
                if (!"sys_oil_001".equals(newBean.questionToSystemSn)) {
                    continue;
                }
                List<DetectionNewBean.QuestionToItemDetectionBean> qList = new ArrayList<>();
                DetectionNewBean.QuestionToItemDetectionBean qBean = new DetectionNewBean.QuestionToItemDetectionBean();
                List<DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean> listBeans = new ArrayList<>();
                DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean listBean = new DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean();
                listBean.answer = oil + "";
                listBeans.add(listBean);
                qBean.questionList = listBeans;
                qList.add(qBean);
                newBean.questionToItemDetectionFirstVOList = qList;
                mList.remove(i);
                mList.add(i,newBean);
            }
        }

        if (lightAdapter != null) {
            List<DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean> listBeans = lightAdapter.getmList();
            if (X3StringUtils.isListEmpty(listBeans)) {
                listBeans = new ArrayList<>();
            }

            for (int i = 0; i < listBeans.size(); i++) {
                DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean listBean = listBeans.get(i);
                if (listBean == null) {
                    continue;
                }
                if (X3StringUtils.isEmpty(listBean.answer)) {
                    continue;
                }
                listBean.answer = listBean.answer.replaceAll("\\. ","_");
                listBeans.remove(i);
                listBeans.add(i,listBean);
            }

            for (int i = 0; i < mList.size(); i++) {
                DetectionNewBean newBean = mList.get(i);
                if (!"sys_light_new_001".equals(newBean.questionToSystemSn)) {
                    continue;
                }
                List<DetectionNewBean.QuestionToItemDetectionBean> qList = new ArrayList<>();
                DetectionNewBean.QuestionToItemDetectionBean qBean = new DetectionNewBean.QuestionToItemDetectionBean();
                qBean.questionList = listBeans;
                qBean.sn = "sys_light_new_001";
                qList.add(qBean);
                newBean.questionToItemDetectionFirstVOList = qList;
                mList.remove(i);
                mList.add(i,newBean);
            }
        }

        if (thingAdapter != null) {
            List<DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean> questionListBeans = thingAdapter.getmList();
            for (int i = 0; i < mList.size(); i++) {
                DetectionNewBean newBean = mList.get(i);
                if (!"sys_thing_001".equals(newBean.questionToSystemSn)) {
                    continue;
                }
                List<DetectionNewBean.QuestionToItemDetectionBean> qList = new ArrayList<>();
                DetectionNewBean.QuestionToItemDetectionBean qBean = new DetectionNewBean.QuestionToItemDetectionBean();
                qBean.questionList = questionListBeans;
                qList.add(qBean);
                newBean.questionToItemDetectionFirstVOList = qList;
                List<String> picList = new ArrayList<>();

                if (richPicAdapter != null) {
                    if (!X3StringUtils.isListEmpty(richPicAdapter.getImageList())) {
                        for (AloneImageAndRecordBean bean : richPicAdapter.getImageList()) {
                            if (bean.getUploadStatus() == 1){
                                picList.add(bean.getHttpPath());
                            }
                        }
                    }
                }
                newBean.urlList = picList;
                if((picList != null && picList.size() > 0) && (questionListBeans != null)){
                    boolean select = false;
                    for (DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean bean : questionListBeans){
                        if (bean != null && bean.selected){
                            select = true;
                            break;
                        }
                    }
                    if (!select){
                        //如果拍摄了照片，那么必须选择贵重物品
                        tipSelectRichThing();
                        commitFlag = false;
                        return;
                    }
                }
                mList.remove(i);
                mList.add(i,newBean);
            }
        }

        if (bodyAdapter != null) {
            List<DetectionNewBean.QuestionToItemDetectionBean> detectionBeans = bodyAdapter.getmList();
            for (int i = 0; i < mList.size(); i++) {
                DetectionNewBean newBean = mList.get(i);
                if (!"sys_feature_new_001".equals(newBean.questionToSystemSn)) {
                    continue;
                }
                newBean.questionToItemDetectionFirstVOList = detectionBeans;
                mList.remove(i);
                mList.add(i,newBean);
            }
        }

        if (toolAdapter != null) {
            List<DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean> questionListBeans = toolAdapter.getmList();
            for (int i = 0; i < mList.size(); i++) {
                DetectionNewBean newBean = mList.get(i);
                if (!"sys_tools_001".equals(newBean.questionToSystemSn)) {
                    continue;
                }
                List<DetectionNewBean.QuestionToItemDetectionBean> qList = new ArrayList<>();
                DetectionNewBean.QuestionToItemDetectionBean qBean = new DetectionNewBean.QuestionToItemDetectionBean();
                qBean.questionList = questionListBeans;
                qList.add(qBean);
                newBean.questionToItemDetectionFirstVOList = qList;
                mList.remove(i);
                mList.add(i,newBean);
            }
        }

        String inputContent = et_input.getText().toString();
        if (X3StringUtils.isEmpty(inputContent)) {
            inputContent = "";
        }
        for (int i = 0; i < mList.size(); i++) {
            DetectionNewBean newBean = mList.get(i);
            if (!"sys_remark_001".equals(newBean.questionToSystemSn)) {
                continue;
            }
            List<DetectionNewBean.QuestionToItemDetectionBean> qList = new ArrayList<>();
            DetectionNewBean.QuestionToItemDetectionBean qBean = new DetectionNewBean.QuestionToItemDetectionBean();
            List<DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean> listBeans = new ArrayList<>();
            DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean listBean = new DetectionNewBean.QuestionToItemDetectionBean.QuestionListBean();
            listBean.answer = inputContent;
            listBeans.add(listBean);
            qBean.questionList = listBeans;
            qList.add(qBean);
            newBean.questionToItemDetectionFirstVOList = qList;
            mList.remove(i);
            mList.add(i,newBean);
        }

        if (mPresenter != null && commitFlag) {
            mPresenter.saveDetectionFirstInfo(mList,receiveBaseId);
        }
    }

    private void tipSelectRichThing(){

        rv_check.reset();

        /**
         * 先回到顶部
         */
        nv_view.scrollTo(0,0);

        nv_view.post(() -> {
            int[] location = new int[2];
            rl_thing.getLocationOnScreen(location);
            nv_view.smoothScrollTo(0,location[1] - X3ScreenUtils.dipToPx(50, X3FirstAloneActivity.this) - X3StatusBarUtil.getStatusBarHeight(X3FirstAloneActivity.this));
        });

        ToastUtils.show(getString(R.string.first_alone_thing_select_tips));

    }

    @Override
    public void saveDetectionFirstInfoSuccess() {
        rv_check.reset();
        DeleteFriends deleteFriends = new DeleteFriends("Refresh_First_Alone");
        EventBus.getDefault().post(deleteFriends);

        Intent intent = new Intent(this, X3WorkFinishActivity.class);
        intent.putExtra("type", X3WorkType.Type_First);
        intent.putExtra("receiveBaseId",receiveBaseId);
        startActivity(intent);
        if (isFirst) {
            ToastUtils.show(getString(R.string.x3_finish_first_report_notice));
        }
        finish();
    }

    //贵重物品打开相机
    @Override
    public void iOnItemCameraClick(int imageIndex) {
        isRich = true;
        isLight = false;
        richPicIndex = imageIndex;
        startCameraView(6,imageIndex);
    }

    @Override
    public void iOnDeleteClick(long resId, int position, int titleIndex, String path) {
//        richPicShowList.remove(position);
//        richPicAdapter.changeData(richPicShowList);
    }

    @Override
    public void iOnAgainUploadImage(String path, int titleIndex, int imageIndex) {
        saveRichPicture(path);
    }

    @Override
    public void iOnDeleteImage(int titleIndex, List<AloneImageAndRecordBean> mList) {
        richPicShowList.clear();
        richPicShowList.addAll(mList);
    }

    /**
     * 贵重物品刷新pic
     * @param cameraBean
     * @param imageIndex
     */
    private void onRichGetPicRefreshPicRlv(CameraBean cameraBean,int imageIndex){
        List<String> pList = (List<String>) cameraBean.cameraData;
        showRichPics(pList,false);
    }

    /**
     *
     * @param pList
     * @param isPicUpLoaded 图片是否已经上传完成，从编辑进来的图片其状态为上传完成，
     */
    private void showRichPics(List<String> pList,boolean isPicUpLoaded){
        List<AloneImageAndRecordBean> addImageList = new ArrayList<>();
        if (pList != null && pList.size() > 0){
            for (String path : pList){
                if (isPicUpLoaded){
                    addImageList.add(new AloneImageAndRecordBean(path,path,0,1));
                } else {
                    addImageList.add(new AloneImageAndRecordBean(path,path,0,0));
                    saveRichPicture(path);
                }
            }
        }
        if (richPicShowList == null){
            richPicShowList = addImageList;
        }else{
            richPicShowList.addAll(addImageList);
        }
        richPicAdapter.changeData(richPicShowList);
    }

    private void saveRichPicture(String originPath ) {
        try {
            File imgFile = new File(originPath);

            Luban.with(this)
                    .load(imgFile.getPath())
                    .ignoreBy(100)
                    .setTargetDir(X3FileUtils.getStoragePath(this, X3FileUtils.MECHANIC_PHOTO_STORAGE_PATH))
                    .filter(path1 -> !(TextUtils.isEmpty(imgFile.getPath()) || imgFile.getPath().toLowerCase().endsWith(".gif")))
                    .setCompressListener(new OnCompressListener() {
                        @Override
                        public void onStart() {
                        }

                        @Override
                        public void onSuccess(File file) {
                            upLoadRichFiles(originPath,file.getPath());
                        }

                        @Override
                        public void onError(Throwable e) {
                        }
                    }).launch();
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void upLoadRichFiles(String originPath,String compressPath){
        File imgFile = new File(compressPath);

        RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), imgFile);

        String filename = null;
        try {
            filename = URLEncoder.encode(imgFile.getName(), "UTF-8");

            MultipartBody.Part fileBody = MultipartBody.Part.createFormData("multipartFile", filename, requestBody);

            Map<String, RequestBody> map = new HashMap<>();

            map.put("description",RequestBody.create(MediaType.parse("multipart/form-data"), "初检图片"));

            map.put("ossBucketName",RequestBody.create(MediaType.parse("multipart/form-data"), "SERVICE_PIC"));

            NetWorkHttp.getApi().uploadFileAws(map,fileBody,new HashMap<>())
                    .compose(RxSchedulersHelper.defaultComposeRequest())
                    .compose(((X3IBaseView)X3FirstAloneActivity.this).bindToLife())
                    .subscribe(new HttpCallBack<AwsFileBean>() {
                        @Override
                        protected void onDone(AwsFileBean awsFileBean) {
                            if (awsFileBean == null) {
                                return;
                            }
                            onUploadDone(awsFileBean,originPath);
                        }

                        @Override
                        protected String LoadingMessage() {
                            return null;
                        }

                        @Override
                        protected void NoNetCallBack() {
                            super.NoNetCallBack();
//                            rv_check.reset();
                        }

                        @Override
                        protected void showError(String error) {
                            rv_check.reset();
                        }
                    });

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    /**
     * 上传完pic后刷新图片状态
     */
    private void onUploadDone(AwsFileBean awsFileBean,String path){
        List<AloneImageAndRecordBean> mList = new ArrayList<>();
        List<AloneImageAndRecordBean> addImageList = new ArrayList<>();
        addImageList.add(new AloneImageAndRecordBean(path,awsFileBean.downloadUrl,awsFileBean.id,1));
        if (richPicAdapter == null){
            return;
        }

        /**
         * 不要在这个地方使用
         * List<AloneImageAndRecordBean> mLists = picAdapter.getImageList();
         * 获取list，这样会因为异步造成获得的数据是另一个线程add或者remove或者clear的list数据，会出现数据不准确
         * 可以考虑使用同步锁
         */
        if (richPicShowList == null || richPicShowList.size() == 0){
            mList = addImageList;
        } else {
            int mCurrent = -1;
            for(int i = 0; i < richPicShowList.size(); i++){
                if (richPicShowList.get(i).getId() > 0){
                    if (richPicShowList.get(i).getPath().equals(path) && richPicShowList.get(i).getId() == awsFileBean.id) {
                        Log.e("edite_pic","修改相同的图片 = " + richPicShowList.get(i).getPath());

                        mCurrent = i;
                        break;
                    }
                } else {
                    if (richPicShowList.get(i).getPath().equals(path)) {
                        mCurrent = i;
                        break;
                    }
                }
            }
            if(mCurrent == -1){
                return;
            }
            richPicShowList.remove(mCurrent);
            richPicShowList.add(mCurrent,new AloneImageAndRecordBean(path,awsFileBean.downloadUrl,awsFileBean.id,1));
            mList = richPicShowList;
        }
//        showBtnStatus();
        richPicAdapter.changeData(mList);
    }
}